#######################################################
# The class of Finite & Stochastic-Time DEVS  
# Author: moonho.hwang@gmail.com
#   Date: Oct.19.2011
#######################################################
from XSY.DEVS.FSDEVS import *

class FSTDEVS(FSDEVS):
   ''' the class of finite & real-time DEVS M=(X,Y,S,tau,delta_0, delta_x,delta_y). Even though it is derived from FSDEVS, the characteristic functions delta_0, delta_x, and delta_y don't have stochastic features any more, while tau returns the random number defined by rv_tau. 
Since the verification can be done in the way of FSDEVS, the non stochastic functions delta_0, delta_x, and delta_y are interpreted in rv_delta_0, delta_x, and rv_delta_y, respectively via generating reachabilty graph of FSDEVS. The users need to override the functions of M instead of these rv_{delta_{0,x,y} }. '''
   def __init__(m, name, parent=None):
      '''constructor:'''
      FSDEVS.__init__(m, name, parent), 
  
   def rv_delta_0(m):
      '''the initial state probability''' 
      m.delta_0()
      return m.get_state()
   
   def rv_delta_x(m, x):
      '''the random variables of the next state and reschedule triggered by an external event x'''
      rho = m.delta_x(x); # the rho is determined in it.
      return DRV({(rho,m.get_state()):1})

   def rv_delta_y(m):
      '''the random variable for output and internal state transition''' 
      y=m.delta_y()
      return DRV({(y,m.get_state()):1})

   ############################################################################################### 
   def delta_0(m):
      '''reset the initial state'''      
      raise Exception("%s is not overrided!"%function_name())

   def delta_x(m, x):
      '''the external transition'''
      raise Exception("%s is not overrided!"%function_name())
      #return (True, m.get_state())

   def delta_y(m):
      '''the output and internal transition'''
      raise Exception("%s is not overrided!"%function_name())
      #return (m.lambda(), m.get_state())

   def set_state(m, n):
      '''override function to set the next state n'''
      raise Exception("%s is not overrided!"%function_name())

   def get_state(m):
      '''override function to get the current state'''
      raise Exception("%s is not overrided!"%function_name())

if __name__ == "__main__":
   print 'mini test of FSTDEVS'
   fg = FSTDEVS("hmh")
   print fg

